package com.gilgamesh.mall.product.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gilgamesh.mall.product.sql.ProductSql;
import com.gilgamesh.mall.sdk.bean.product.ProductEntity;
import com.gilgamesh.mall.sdk.dto.product.ProductDTO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;

/**
 * Created by Peiyao.Wang on 2021/1/12
 *
 * @author Peiyao.Wang
 * @date 2021/1/12
 */
@Mapper
public interface ProductDao extends BaseMapper<ProductEntity> {
    @Results(
            id = "productDTOMap",value = {
            @Result(column = "id" ,jdbcType = JdbcType.BIGINT,javaType = Long.class,property = "id"),
            @Result(column = "product_code" ,jdbcType = JdbcType.VARCHAR,javaType = String.class,property = "productCode"),
            @Result(column = "classfic3_id",jdbcType = JdbcType.BIGINT,javaType = Long.class,property = "classfic3Id"),
            @Result(column = "classfic2_id",jdbcType = JdbcType.BIGINT,javaType = Long.class,property = "classfic2Id"),
            @Result(column = "classfic_id",jdbcType = JdbcType.BIGINT,javaType = Long.class,property = "classficId"),
            @Result(column = "shop_code",jdbcType = JdbcType.VARCHAR,javaType = String.class,property = "shopCode"),
            @Result(column = "create_time",jdbcType = JdbcType.DATETIMEOFFSET,javaType = java.util.Date.class,property = "createTime"),
        }
    )
    @SelectProvider(type = ProductSql.class , method = "listProducts")
    List<ProductDTO> listProducts(ProductEntity entity);

    @Select("select * from t_product where id =#{id}")
    ProductDTO getById(Long id);

    @Insert("insert into t_product values('#{id}','#{productCode}','#{classfic3Id}','#{classfic2Id}','#{classficId}','#{shopCode}','#{createTime}')")
    int add(ProductEntity entity);

    @Select("select * from `t_product` limit #{s},#{l}")
    List<ProductDTO> listV2(@Param(value = "s") Integer s , @Param(value = "l") Integer l);
}
